<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('微信用户列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>用户昵称：</label>
                            <input type="text" name="nickName"/>
                        </li>
                        <li>
                            <label>用户状态：</label>
                            <select name="status" th:with="type=${@dict.getType('companion_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="wx:user:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var removeFlag = [[${@permission.hasPermi('wx:user:remove')}]];
    var detailFlag = [[${@permission.hasPermi('wx:user:detail')}]];

    var genderDatas = [[${@dict.getType('wx_gender')}]];
    var statusDatas = [[${@dict.getType('companion_status')}]];
    var delFalgDatas = [[${@dict.getType('companion_flag')}]];
    var prefix = ctx + "wx/user";

    $(function () {
        var options = {
            url: prefix + "/list",
            removeUrl: prefix + "/remove",
            detailUrl: prefix + "/detail/{id}",
            exportUrl: prefix + "/export",
            modalName: "用户列表",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '编号',
                    visible: false
                },
                {
                    field: 'openId',
                    title: 'openId'
                },
                {
                    field: 'nickName',
                    title: '昵称'
                },
                {
                    field: 'photo',
                    title: '头像',
                    formatter: function (value, row,index){
                        return '<img src="'+value+'" style="width: 50px;height: 50px;"/>';
                    }
                },
                {
                    field: 'gender',
                    title: '性别',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(genderDatas, value);
                    }
                },
                {
                    field: 'status',
                    title: '用户状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'delFlag',
                    title: '是否删除',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(delFalgDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var status_btn = row.status == 1 ? '✔ 加入黑名单' : '✖ 移出黑名单'
                        var status_class = row.status == 1 ? 'btn btn-primary btn-xs ' + removeFlag : 'btn btn-danger btn-xs ' + removeFlag
                        actions.push('<a class="'+ status_class +'" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa"></i>' + status_btn + '</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i>详细</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>